package com.dynamo.transport.network.practise.socksproxy;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
import org.jboss.netty.handler.codec.socks.SocksInitRequestDecoder;
import org.jboss.netty.handler.codec.socks.SocksMessageEncoder;

/**
 * @author duanyimiao
 * @create 2018-11-21 5:41 PM
 * @description
 **/
public class SocksProxyPipelineFactory implements ChannelPipelineFactory {

    private ClientSocketChannelFactory cf;

    public SocksProxyPipelineFactory(ClientSocketChannelFactory cf){
        this.cf = cf;
    }

    @Override
    public ChannelPipeline getPipeline() {
        ChannelPipeline pipeline = Channels.pipeline();
        //初始请求 handler
        pipeline.addLast(SocksInitRequestDecoder.getName(),new SocksInitRequestDecoder());
        pipeline.addLast(SocksMessageProxyEncoder.getName(),new SocksMessageProxyEncoder());
        pipeline.addLast(SocksServerHandler.getName(),new SocksServerHandler(cf));
        return pipeline;
    }
}
